package com.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.ApiResult;
import com.exam.entity.User;
import com.exam.service.UserService;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shenyang
 * @create 2022-11-01 19:14
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/user/{page}/{size}")
    public ApiResult getUserInfo(@PathVariable int page,@PathVariable int size){
        Page<User> userPage = new Page<User>(page,size);
        IPage<User> users = userService.findAll(userPage);
        return ApiResultHandler.buildApiResult(200,"用户信息查询成功",users);
    }

    @RequestMapping("/user/{page}/{size}/{status}")
    public ApiResult getUserInfoByStatus(@PathVariable int page,@PathVariable int size,@PathVariable String status){
        Page<User> userPage = new Page<User>();
        Page<User> users = userService.findByStatus(userPage,status);
        return ApiResultHandler.buildApiResult(200,"用户信息查询成功",users);
    }
    @RequestMapping("/user")
    public ApiResult get(){
        System.out.println("执行了get（）");
        return ApiResultHandler.buildApiResult(200,"用户信息查询成功",12);
    }
}
